'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	const { courseId, courseInfo } = event
	
	try {
		// 构建更新数据
		const { _id, ...updateData } = {
			...courseInfo,
			price: Number(courseInfo.price),
			duration: Number(courseInfo.duration),
			updateTime: Date.now()
		}
		
		// 更新课程信息
		await db.collection('courses').doc(courseId).update(updateData)
		
		return {
			code: 0,
			msg: '更新成功',
			data: null
		}
	} catch (e) {
		console.error('更新课程失败', e)
		return {
			code: -1,
			msg: e.message || '更新失败',
			data: null
		}
	}
}; 